//
//  Extension.m
//  weibo
//
//  Created by 沈振邦 on 15/4/29.
//  Copyright (c) 2015年 szb. All rights reserved.
//

#import "UIBarButtonItem+Extension.h"
#import "BPNavButtonView.h"

@implementation  UIBarButtonItem (Extension)

+(UIBarButtonItem *)itemWithButtonName:(NSString *)title tatget:(id)target action:(SEL)action
{
    BPNavButtonView *button = [[BPNavButtonView alloc] init];
    [button setTitle:title forState:UIControlStateNormal];
    [button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    return [[UIBarButtonItem alloc] initWithCustomView:button];
}

+(UIBarButtonItem *)itemWithButtonName:(NSString *)title withPic:(NSString *)navButtonPic tatget:(id)target action:(SEL)action
{
    BPNavButtonView *button = [[BPNavButtonView alloc] init];
    [button setTitleEdgeInsets:UIEdgeInsetsMake(0, 5, 0, 0)];
    [button setImageEdgeInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
    [button setTitle:title forState:UIControlStateNormal];
    [button setImage:[UIImage imageNamed:navButtonPic] forState:UIControlStateNormal];
    [button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    return [[UIBarButtonItem alloc] initWithCustomView:button];
}


+ (UIBarButtonItem *)itemWithImageName:(NSString *)imageName highImageName:(NSString *)highImageName target:(id)target action:(SEL)action
{
    UIButton *button = [[UIButton alloc] init];
    [button setBackgroundImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
    [button setBackgroundImage:[UIImage imageNamed:highImageName] forState:UIControlStateHighlighted];
    
    // 设置按钮的尺寸为背景图片的尺寸
    button.size = button.currentBackgroundImage.size;
    
    // 监听按钮点击
    [button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    return [[UIBarButtonItem alloc] initWithCustomView:button];
}

@end
